﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Transactions;
using System.Web.Mvc;
using eCommMongo.Core.Data;
using eCommMongo.Core.Domain;
using eCommMongo.Core.Domain.Addresses;
using eCommMongo.Core.Domain.Brands;
using eCommMongo.Core.Domain.Categorys;
using eCommMongo.Core.Domain.Customers;
using eCommMongo.Core.Domain.Messges;
using eCommMongo.Core.Domain.Orders;
using eCommMongo.Core.Domain.Payments;
using eCommMongo.Core.Domain.Pictures;
using eCommMongo.Core.Domain.Posts;
using eCommMongo.Core.Domain.Products;
using eCommMongo.Core.Domain.Securitys;
using eCommMongo.Core.Domain.Shippings;
using eCommMongo.Core.Domain.ShoppingCarts;
using eCommMongo.Core.Domain.Shops;
using eCommMongo.Core.Domain.Tags;
using eCommMongo.Core.Domain.Tradings;
using eCommMongo.Service.Customers;
using eCommMongo.Service.Securitys;
using yiCommerce.Core;

namespace eCommMongo.Web.Areas.Install.Controllers
{
    public class InstallController: Controller
    {
        private ICustomerService _customerService;

        private IMongoRepository<Tag> _tagsRep;
        private IMongoRepository<PostPointDetail> _statusPointDetailRep;
        private IMongoRepository<CustomerLogo> _customerLogoRep;
        private IMongoRepository<CustomerRole> _customerRoleRepository;
        private IMongoRepository<Customer> _customerRepository;
        private IMongoRepository<Shop> _shopRepository;
        private IMongoRepository<ProductAttribute> _productAttributeRepository;
        private IMongoRepository<SpecificationAttribute> _speficationAttributreRepostiory;
        private IMongoRepository<SpecificationAttributeOption> _speficationAttributreOptionRepostiory;
        private IMongoRepository<Order> _orderRep;
        private IMongoRepository<Trading> _tradingRep;
        private IMongoRepository<SystemSetting> _systemSettingRep;
        private IMongoRepository<AlipayPaymethodSetting> _alipaysettingrep;
        private IMongoRepository<Brand> _brandRep;
        private IMongoRepository<Category> _catRep;
        private IMongoRepository<Address> _addressRep;
        private IMongoRepository<ShoppingCartItem> _shoppingCartItemRep;
        private IMongoRepository<Product> _productRepository;
        private IMongoRepository<ProductVariant> _productVariantRepository;
        private IMongoRepository<Picture> _picturerep;
        private IMongoRepository<ProductPicture> _productpicturerep;
        private IMongoRepository<PermissionRecord> _permissionRecordRep;
        private IMongoRepository<Shipment> _shipmentRecordRep;
        private IMongoRepository<PostPicture> _statusPicRep;
        private IMongoRepository<Post> _statusRep;
        //private IMongoRepository<FriendShip> _friendShipRep;
        private IEncryptionService _encryptionService;
        private IMongoRepository<Message> _messageRep;

        public InstallController(

            //IMongoRepository<FriendShip> friendShipRep,
            IMongoRepository<Post> statusRep,
            IMongoRepository<PostPicture> statusPicRep,
            IMongoRepository<Shipment> shipmentRep,
            IMongoRepository<PermissionRecord> permissionRecordRep,
            IEncryptionService encryptionService,
            IMongoRepository<CustomerRole> customerRoleRepository, 
            IMongoRepository<Customer> customerRepository,
            IMongoRepository<Shop> shopRepository, 
            IMongoRepository<ProductAttribute> productAttributeRepository,
            IMongoRepository<SpecificationAttribute> speficationAttributreRepostiory,
            IMongoRepository<SpecificationAttributeOption> speficationAttributreOptionRepostiory,
            IMongoRepository<Order> orderRep, 
            IMongoRepository<Trading> tradingRep, 
            IMongoRepository<SystemSetting> systemSettingRep, 
            IMongoRepository<AlipayPaymethodSetting> alipaysettingrep, 
            IMongoRepository<Brand> brandRep, 
            IMongoRepository<Category> catRep, 
            IMongoRepository<Address> addressRep, 
            IMongoRepository<ShoppingCartItem> shoppingCartItemRep, 
            IMongoRepository<Product> productRepository, 
            IMongoRepository<ProductVariant> productVariantRepository, 
            IMongoRepository<Picture> picturerep, 
            IMongoRepository<ProductPicture> productpicturerep, 
            IMongoRepository<Message> messageService, 
            IMongoRepository<CustomerLogo> customerLogoRep, 
            IMongoRepository<PostPointDetail> statusPointDetailRep, 
            IMongoRepository<Tag> tagsRep, ICustomerService customerService)
        {
            //_friendShipRep = friendShipRep;
            _statusRep = statusRep;
            _statusPicRep = statusPicRep;
            _shipmentRecordRep = shipmentRep;
            _permissionRecordRep = permissionRecordRep;
            _encryptionService = encryptionService;
            _customerRoleRepository = customerRoleRepository;
            _customerRepository = customerRepository;
            _shopRepository = shopRepository;
            _productAttributeRepository = productAttributeRepository;
            _speficationAttributreRepostiory = speficationAttributreRepostiory;
            _speficationAttributreOptionRepostiory = speficationAttributreOptionRepostiory;
            _orderRep = orderRep;
            _tradingRep = tradingRep;
            _systemSettingRep = systemSettingRep;
            _alipaysettingrep = alipaysettingrep;
            _brandRep = brandRep;
            _catRep = catRep;
            _addressRep = addressRep;
            _shoppingCartItemRep = shoppingCartItemRep;
            _productRepository = productRepository;
            _productVariantRepository = productVariantRepository;
            _picturerep = picturerep;
            _productpicturerep = productpicturerep;
            _messageRep = messageService;
            _customerLogoRep = customerLogoRep;
            _statusPointDetailRep = statusPointDetailRep;
            _tagsRep = tagsRep;
            _customerService = customerService;
        }

        public ActionResult Index()
        {
            using (var trans = new TransactionScope())
            {

              

                DeleteOrders();
                DeleteTradings();
                DeleteSystemSetting();
          
                DeleteSpecificationAttribute();

                DeleteShipment();

             
                DeleteProductAttribute();

               
                DeleteStatusPointDetail();
                DeleteStatuses();


                DeleteProduct();
              
                DeleteOrder();

                DeleteCustomerRole();
                DeleteCustomer();
                DeleteBrand();
                DeleteCategory();
                DeleteAlipayPaymethodSetting();
               
             
                DeleteFriendShip();
                DeleteMessages();

                DeleteTags();
                InstallSystemSetting();
                InstallAlipayPaymethodSetting();
                InstallBrand();
                InstallCategory();

                InstallPermissionRecordRoleMapping();
                InstallMessages();

                var admintratorId = InstallAdministrator();
                var shopOwenerId = InstallShopOwner();
                var customerId = InstallCustomer();

                InstallProductAttribute();
                InstallShop(shopOwenerId, admintratorId, customerId);

                //var customerId = InstallCustomer();
                InstallSpecificationAttributes();
                InstallTags(admintratorId);

                trans.Complete();
            }
            //return View();
            //return View("PluginSysWebRegForm.Views.RegForm.Index");
            return View("~/Areas/Install/Views/Install/Index.cshtml");


        }

        private void InstallTags(string admintratorId)
        {
            var newTag = new Tag()
                {
                    CreateAt = DateTime.Now,
                    Creator = new Customer() { Id = admintratorId },
                    Deleted = false,
                    TagName = "动漫",
                    TagValue = "动漫",
                    CountTaged = 0,
                };
            _tagsRep.Insert( newTag);


            newTag = new Tag()
            {
                CreateAt = DateTime.Now,
                Creator = new Customer() { Id = admintratorId },
                Deleted = false,
                TagName = "音乐",
                TagValue = "音乐",
                CountTaged = 0,
            };
            _tagsRep.Insert( newTag);

            newTag = new Tag()
            {
                CreateAt = DateTime.Now,
                Creator = new Customer() { Id = admintratorId },
                Deleted = false,
                TagName = "健身",
                TagValue = "健身",
                CountTaged = 0,
            };
            _tagsRep.Insert( newTag);

            newTag = new Tag()
            {
                CreateAt = DateTime.Now,
                Creator = new Customer() { Id = admintratorId },
                Deleted = false,
                TagName = "烘焙",
                TagValue = "烘焙",
                CountTaged = 0,
            };
            _tagsRep.Insert(newTag);
        }

        private void DeleteTags()
        {
            var items = _tagsRep.Table().ToList();
            foreach (var item in items)
            {
                _tagsRep.Delete( item.Id);
            }
        }

        private void DeleteStatusPointDetail()
        {
            var items = _statusPointDetailRep.Table().ToList();
            foreach (var item in items)
            {
                _statusPointDetailRep.Delete( item.Id);
            }

        }


        private void InstallMessages()
        {
            var msg = new Message()
                {
                    Languageid = 0,
                    ResourceName = "CustomerRegistrationService_ValidateCustomer_LoginFailed",
                    ResourceValue = "login failed"
                };
            _messageRep.Insert(msg);
            msg = new Message()
                {
                    Languageid = 0,
                    ResourceName = "Login_NeedEmailAddress",
                    ResourceValue = "Please supply your Email address."
                };
            _messageRep.Insert(msg);


            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Login_NeedPassword",
                ResourceValue = "Please supply your Password."
            };
            _messageRep.Insert(msg); 
            
            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Login_Email",
                ResourceValue = "Email"
            };
            _messageRep.Insert(msg);

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Login_Password",
                ResourceValue = "Password"
            };
            _messageRep.Insert(msg);


            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Login_Login",
                ResourceValue = "Sign in"
            };
            _messageRep.Insert(msg);


            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Login_Title",
                ResourceValue = "Please sign in"
            };
            _messageRep.Insert(msg);


            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Register_Title",
                ResourceValue = "Please regist"
            };
            _messageRep.Insert(msg);


            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Register_UserName",
                ResourceValue = "UserName"
            };
            _messageRep.Insert(msg);



            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Register_Email",
                ResourceValue = "Email"
            };
            _messageRep.Insert(msg);


            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Register_Password",
                ResourceValue = "Password"
            };
            _messageRep.Insert(msg);



            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Register_NeedUserName",
                ResourceValue = "Please supply your user name_"
            };
            _messageRep.Insert(msg);


            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Register_NeedPassword",
                ResourceValue = "Please supply your password_"
            };
            _messageRep.Insert(msg);


            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Register_NeedEmailAddress",
                ResourceValue = "Please supply your Email address_"
            };
            _messageRep.Insert(msg);


            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Register_Register",
                ResourceValue = "Register"
            };
            _messageRep.Insert(msg);


            msg = new Message()
            {
                Languageid = 0,
                ResourceName = Messages.CustomerRegistrationService_RegisterSuccess,
                ResourceValue = "regist success"
            };
            _messageRep.Insert(msg);


            msg = new Message()
            {
                Languageid = 0,
                ResourceName = Messages.CustomerRegistrationService_RegisterFailed,
                ResourceValue = "regist failed"
            };
            _messageRep.Insert(msg);


            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Cutomer_Logo_Title",
                ResourceValue = "Please Upload Logo"
            };
            _messageRep.Insert(msg);


            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Cutomer_Logo_Save",
                ResourceValue = "Save Logo"
            };
            _messageRep.Insert(msg);


            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Cutomer_Logo_SaveSuccess",
                ResourceValue = "Save Successfully"
            };

            //Customer_Logo_CurrentLogo_Title

            _messageRep.Insert(msg);



            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Customer_Logo_CurrentLogo_Title",
                ResourceValue = "Current Logo"
            };
            _messageRep.Insert(msg);

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Customer_Logo_Upload_Title",
                ResourceValue = "Upload New Logo"
            };
            _messageRep.Insert(msg);


            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "CustomerLogo_Update_Successfully",
                ResourceValue = "Logo Updated Successfully"
            };
            _messageRep.Insert(msg);

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Customer_Info_Intro_Title",
                ResourceValue = "Self Introduction"
            };
            _messageRep.Insert(msg);


            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Customer_Info_NickName_Title",
                ResourceValue = "Nickname"
            };
            _messageRep.Insert(msg);


            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Cutomer_Info_Save",
                ResourceValue = "Save"
            };
            _messageRep.Insert(msg);



            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "CustomerInfo_Update_Successfully",
                ResourceValue = "Customer Info Updated Successfully"
            };
            _messageRep.Insert(msg);


            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Customer_Info_Title",
                ResourceValue = "Please Update Your Info"
            };
            _messageRep.Insert(msg);

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_Product_NeedProductName",
                ResourceValue = "Please supply ProductName_"
            };
            _messageRep.Insert(msg);

            //

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_Product_Create_Button_Title",
                ResourceValue = "Save"
            };
            _messageRep.Insert(msg);


            //Admin_Product_List_ProductName_Title

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_Product_List_ProductName_Title",
                ResourceValue = "ProductName"
            };
            _messageRep.Insert(msg);


            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_Product_List_ProductPictureUrl_Title",
                ResourceValue = "PictureUrl"
            };
            _messageRep.Insert(msg);


            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_Product_List_IsPublished_Title",
                ResourceValue = "IsPublished"
            };
            _messageRep.Insert(msg);


            //Admin_Product_List_Edit_Title

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_Product_List_Edit_Title",
                ResourceValue = "Edit"
            };
            _messageRep.Insert(msg);


            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_Product_NeedShortDescription",
                ResourceValue = "Please supply Short Description_"
            };
            _messageRep.Insert(msg);

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_Product_NeedFullDescription",
                ResourceValue = "Please supply Full Description_"
            };
            _messageRep.Insert(msg);

            //Admin_Product_Create_Title


            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_Product_Create_Title",
                ResourceValue = "Create Product"
            };
            _messageRep.Insert(msg);

            //

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_Product_Edit_ProductInfo_Tab",
                ResourceValue = "Product Info"
            };
            _messageRep.Insert(msg);


            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_Product_Edit_ProductPicture_Tab",
                ResourceValue = "Product Picture"
            };
            _messageRep.Insert(msg);


            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_Product_Edit_ProductSpecificationAttribute_Tab",
                ResourceValue = "ProductSpecificationAttribute"
            };
            _messageRep.Insert(msg);


            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_Product_Edit_Save_Button",
                ResourceValue = "Save"
            };
            _messageRep.Insert(msg);


            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "ProductUpdateInfoSuccess",
                ResourceValue = "Product Info Update successfully"
            };

            _messageRep.Insert(msg);

            //Admin_Product_Edit_Title

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_Product_Edit_Title",
                ResourceValue = "Edit Product"
            };
            _messageRep.Insert(msg);

            //Admin_Product_List_CreateProduct
            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_Product_List_CreateProduct",
                ResourceValue = "Create New Product"
            };
            _messageRep.Insert(msg);


            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_ProductVariant_List_Name",
                ResourceValue = "Name"
            };
            _messageRep.Insert(msg);


            //Admin_ProductVariant_List_Sku

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_ProductVariant_List_Sku",
                ResourceValue = "Sku"
            };
            _messageRep.Insert(msg);


            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_ProductVariant_NeedName",
                ResourceValue = "Please supply name_"
            };
            _messageRep.Insert(msg);

            //Admin_ProductVariant_NeedDigit
            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_ProductVariant_PriceFormatError",
                ResourceValue = "Price format wrong"
            };
            _messageRep.Insert(msg);


            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_Product_Edit_ProductVariant_Tab",
                ResourceValue = "Product Variant"
            };
            _messageRep.Insert(msg);

            //Admin_ProductVariant_NeedPicture

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_ProductVariant_NeedPicture",
                ResourceValue = "Plesase upload picture"
            };
            _messageRep.Insert(msg);

            //

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_ProductVariant_StockQuantityFormatError",
                ResourceValue = "stock quantity format error"
            };
            _messageRep.Insert(msg);

            //

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_ProductVariant_DisplayOrderFormatError",
                ResourceValue = "display order format error"
            };
            _messageRep.Insert(msg);


            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "ProductVariantCreateInfoSuccess",
                ResourceValue = "save product variant successfully"
            };
            _messageRep.Insert(msg);

            //Admin_ProductVariant_Create_Button_Title
            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_ProductVariant_Create_Button_Title",
                ResourceValue = "save"
            };
            _messageRep.Insert(msg);

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_Productvariant_Create_Title",
                ResourceValue = "create product variant"
            };
            _messageRep.Insert(msg);

            //Admin_ProductVariant_Edit_Title
            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_ProductVariant_Edit_Title",
                ResourceValue = "edit product variant"
            };
            _messageRep.Insert(msg);

            //Admin_ProductVariant_Edit_Tab_Title

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_ProductVariant_Edit_Tab_Title",
                ResourceValue = "product variant"
            };
            _messageRep.Insert(msg);

            //Admin_ProductVariantAttribute_Edit_Tab_Title

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_ProductVariantAttribute_Edit_Tab_Title",
                ResourceValue = "product variant attribute"
            };
            _messageRep.Insert(msg);

            //ProductVariantUpdateSuccess
            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "ProductVariantUpdateSuccess",
                ResourceValue = "product variant updated successfully"
            };
            _messageRep.Insert(msg);

            //Admin_ProductVariant_Save_Back

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_ProductVariant_Save_Back",
                ResourceValue = "back"
            };
            _messageRep.Insert(msg);

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_ProductVariantAttribute_Save_Back",
                ResourceValue = "back"
            };
            _messageRep.Insert(msg);

            //"

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "admin_productvariantattribute_attribute",
                ResourceValue = "attribute"
            };
            _messageRep.Insert(msg);
            //admin_productvariantattribute_attributecontroltype

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "admin_productvariantattribute_attributecontroltype",
                ResourceValue = "attribute control type"
            };
            _messageRep.Insert(msg);


            //admin_productvariantattribute_values
            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "admin_productvariantattribute_values",
                ResourceValue = "values"
            };
            _messageRep.Insert(msg);

            //admin_productvarinatattribute_create_title
            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "admin_productvarinatattribute_create_title",
                ResourceValue = "create product variant attribute"
            };
            _messageRep.Insert(msg);

            //
            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_ProductVariantAttribute_Create_Button_Title",
                ResourceValue = "save"
            };
            _messageRep.Insert(msg);

            //admin_productvariantattribute_delete_button_title
            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "admin_productvariantattribute_delete_button_title",
                ResourceValue = "delete"
            };
            _messageRep.Insert(msg);

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "ProductVariantAttributeValueDeleteSuccess",
                ResourceValue = "product varinat attribute value deleted successfully"
            };
            _messageRep.Insert(msg);

            //admin_productvariantattribute_delete_confirm

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "admin_productvariantattribute_delete_confirm",
                ResourceValue = "confirm to delete?"
            };
            _messageRep.Insert(msg);


            //Admin_ProductVariant_List_Price

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_ProductVariant_List_Price",
                ResourceValue = "Price"
            };
            _messageRep.Insert(msg);

            //Admin_ProductVariant_List_DisplayOrder
            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_ProductVariant_List_DisplayOrder",
                ResourceValue = "DisplayOrder"
            };
            _messageRep.Insert(msg);

            //Admin_ProductVariant_List_Published   
            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_ProductVariant_List_Published",
                ResourceValue = "Is Published"
            };
            _messageRep.Insert(msg);

            //Admin_ProductVariant_List_Edit_Button_Title
            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_ProductVariant_List_Edit_Button_Title",
                ResourceValue = "Edit"
            };
            _messageRep.Insert(msg);

            //Admin_ProductVariant_List_Create_Button_Title
            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_ProductVariant_List_Create_Button_Title",
                ResourceValue = "Create ProductVariant"
            };
            _messageRep.Insert(msg);

            //admin_productvariantattribute_values_edit_title
            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "admin_productvariantattribute_values_edit_title",
                ResourceValue = "Values Edit"
            };
            _messageRep.Insert(msg);

            //admin_productvariantattribute_delete_title
            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "admin_productvariantattribute_delete_title",
                ResourceValue = "delete"
            };
            _messageRep.Insert(msg);


            //Admin_ProductVariant_List_Delete_Button_Title

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_ProductVariant_List_Delete_Button_Title",
                ResourceValue = "delete"
            };
            _messageRep.Insert(msg);


            //ProductVariantDeleteSuccess

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "ProductVariantDeleteSuccess",
                ResourceValue = "ProductVariant delete successfully"
            };
            _messageRep.Insert(msg);

            //admin_productvariant_delete_confirm

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "admin_productvariant_delete_confirm",
                ResourceValue = "confirm to delete product variant?"
            };
            _messageRep.Insert(msg);

            //admin_product_delete_title
            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "admin_product_delete_title",
                ResourceValue = "delete"
            };
            _messageRep.Insert(msg);

            //admin_product_delete_confirm

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "admin_product_delete_confirm",
                ResourceValue = "confirm to delete product?"
            };
            _messageRep.Insert(msg);


            //ProductDeleteSuccess

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "ProductDeleteSuccess",
                ResourceValue = "product deleted successfully"
            };
            _messageRep.Insert(msg);

            //Admin_Product_Save_Back

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_Product_Save_Back",
                ResourceValue = "back"
            };
            _messageRep.Insert(msg);

            //admin_productvariantvalues_name_title

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "admin_productvariantvalues_name_title",
                ResourceValue = "name"
            };
            _messageRep.Insert(msg);

            //Admin_ProductVariantAttributeValue_NeedValue

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_ProductVariantAttributeValue_NeedValue",
                ResourceValue = "please supply value"
            };
            _messageRep.Insert(msg);

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_ProductVariantAttributeValue_NeedDisplayOrder",
                ResourceValue = "please supply display order"
            };
            _messageRep.Insert(msg);


            //Admin_ProductVariantAttributeValue_DisplayOrderFormatError

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_ProductVariantAttributeValue_DisplayOrderFormatError",
                ResourceValue = "display order format error"
            };
            _messageRep.Insert(msg);


            //Admin_ProductVariant_NeedDisplayOrder


            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_ProductVariant_NeedDisplayOrder",
                ResourceValue = "please supply display order"
            };
            _messageRep.Insert(msg);

            //Admin_ProductVariant_NeedStock

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_ProductVariant_NeedStockQuantity",
                ResourceValue = "please supply stock quantity"
            };
            _messageRep.Insert(msg);


            //Admin_ProductVariant_NeedPrice

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_ProductVariant_NeedPrice",
                ResourceValue = "please supply price"
            };
            _messageRep.Insert(msg);

            //Admin_ProductVariantAttributeValues_Save_Back
            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_ProductVariantAttributeValues_Save_Back",
                ResourceValue = "back"
            };
            _messageRep.Insert(msg);


            //admin_productvariantvalues_displayorder_title
            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "admin_productvariantvalues_displayorder_title",
                ResourceValue = "display order"
            };
            _messageRep.Insert(msg);

            //admin_productvariantattributevalue_delete_title
            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "admin_productvariantattributevalue_delete_title",
                ResourceValue = "delete"
            };
            _messageRep.Insert(msg);


            //
            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "ProductVariantAttributeDeleteSuccess",
                ResourceValue = "product variant attribute delete successfully"
            };
            _messageRep.Insert(msg);


            //admin_productvariantattributevalue_delete_confirm
            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "admin_productvariantattributevalue_delete_confirm",
                ResourceValue = "confirm to delete product variant attribute value?"
            };
            _messageRep.Insert(msg);

            //
            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_ProductPicture_DisplayOrderFormatError",
                ResourceValue = "display order format error"
            };
            _messageRep.Insert(msg);

            //Admin_ProductPicture_NeedDisplayOrder
            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_ProductPicture_NeedDisplayOrder",
                ResourceValue = "please supply display order"
            };
            _messageRep.Insert(msg);


            //

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_ProductPicture_NeedPicture",
                ResourceValue = "please upload picture "
            };
            _messageRep.Insert(msg);

            //"admin_productpicture_displayorder_title
            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "admin_productpicture_displayorder_title",
                ResourceValue = "display order "
            };
            _messageRep.Insert(msg);

            //admin_productpicture_delete_confirm

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "admin_productpicture_delete_confirm",
                ResourceValue = "confirm to delete product picture?"
            };
            _messageRep.Insert(msg);

            //ProductPictureDeletedSuccess

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "ProductPictureDeletedSuccess",
                ResourceValue = "product picture deleted successfully"
            };
            _messageRep.Insert(msg);

            //Admin_ProductVariant_List_StockQuantity

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Admin_ProductVariant_List_StockQuantity",
                ResourceValue = "stock quantity"
            };
            _messageRep.Insert(msg);


            //status_tab_title

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "status_tab_title",
                ResourceValue = "post status"
            };
            _messageRep.Insert(msg);

            //prod_tab_title

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "prod_tab_title",
                ResourceValue = "post product"
            };
            _messageRep.Insert(msg);

            //product_post_placeholder_title

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "product_post_placeholder_title",
                ResourceValue = "product description"
            };
            _messageRep.Insert(msg);

            //ProductStatusUploader_Button_Title 
            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "ProductStatusUploader_Button_Title",
                ResourceValue = "upload product picture"
            };
            _messageRep.Insert(msg);

            //productstatus_productstock_title

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "productstatus_productstock_title",
                ResourceValue = "product stock"
            };
            _messageRep.Insert(msg);

            //productstatus_productprice_title

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "productstatus_productprice_title",
                ResourceValue = "product price"
            };
            _messageRep.Insert(msg);


            //status_product_buy_title
            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "status_product_buy_title",
                ResourceValue = "buy"
            };
            _messageRep.Insert(msg);

            //CommentsAddSuccessfully
            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "CommentsAddSuccessfully",
                ResourceValue = "Comments Added Successfully"
            };
            _messageRep.Insert(msg);

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "RegistFailed",
                ResourceValue = "regist failed"
            };
            _messageRep.Insert(msg);


            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "AvailableTags",
                ResourceValue = "AvailableTags"
            };
            _messageRep.Insert(msg);


            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "ChoosedTags",
                ResourceValue = "ChoosedTags"
            };
            _messageRep.Insert(msg); 
            
            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "Customer_Info_Save",
                ResourceValue = "Save"
            };
            _messageRep.Insert(msg); 

            msg = new Message()
            {
                Languageid = 0,
                ResourceName = "GivePointSuccessfully",
                ResourceValue = "Give Point Successfully"
            };
            _messageRep.Insert(msg);
        }

        private void DeleteMessages()
        {
            var pList = _messageRep.Table().ToList();
            foreach (var p in pList)
            {
                _messageRep.Delete( p.Id.ToString());
            }
        }

        private void DeleteFriendShip()
        {
            //var pList = _friendShipRep.Table(EntityNames.FriendShips).ToList();
            //foreach (var p in pList)
            //{
            //    _friendShipRep.Delete(EntityNames.FriendShips, p.Id.ToString());
            //}
        }

        private void DeleteStatuses()
        {
            var pList = _statusRep.Table().ToList();
            foreach (var p in pList)
            {
                _statusRep.Delete( p.Id);
            }
        }

    

        private void InstallPermissionRecordRoleMapping()
        {

            
            var manageProduct = new PermissionRecord()
                {
                    SystemName = "ManageProduct"

                };


            var manageOrders = new PermissionRecord()
            {
                SystemName = "ManageOrders"

            };

            var accessAdmin = new PermissionRecord()
            {
                SystemName = "AccessAdmin"

            };

            var manageCustomer = new PermissionRecord()
            {
                SystemName = "ManageCustomers"

            };

            
            var manageShipping = new PermissionRecord()
            {
                SystemName = "ManageShipping"

            };

            
            var manageShop = new PermissionRecord()
            {
                SystemName = "ManageShop"

            };



            var administrator = new CustomerRole()
            {
                Active = true,
                SystemName = "Administrators",
                PermissionRecords = new Collection<PermissionRecord>()
                    {
                        manageProduct,
                        manageOrders,
                        accessAdmin,
                        manageCustomer,
                        manageShipping,
                        manageShop
                    }
            };
            _customerRoleRepository.Insert(administrator);

            var shopowner = new CustomerRole()
            {
                Active = true,
                SystemName = "ShopOwner",

                PermissionRecords = new Collection<PermissionRecord>()
                    {
                        manageProduct,
                        manageOrders,
                        accessAdmin,
                        manageShipping,
                    }
            };
            _customerRoleRepository.Insert( shopowner);


            var role = new CustomerRole()
            {
                Active = true,
                SystemName = "Guests"
            };
            _customerRoleRepository.Insert( role);

            role = new CustomerRole()
            {
                Active = true,
                SystemName = "Registered"
            };
            _customerRoleRepository.Insert( role);

        }

   

        private void DeleteCustomerRole()
        {
            var pList = _customerRoleRepository.Table().ToList();
            foreach (var p in pList)
            {
                _customerRoleRepository.Delete( p.Id);
            }
        }

        private string InstallAdministrator()
        {

            var customer = new Customer()
            {
                Active = true,
                Username = "admin",
                Password = _encryptionService.CreatePasswordHash("123456", "aabbcc", "SHA1"),
                Email = "dd@dd.com",
                UserGuid = Guid.NewGuid(),
                Deleted = false,
                CreatedOn = DateTime.Now
            };


            var defaultAddress = new Address()
            {
                FirstName = "Mike",
                LastName = "Yi",
                PhoneNumber = "12345678",
                MobileNumber = "1232323",
                Email = "cc@cc.com",
                Province = "shang hai",
                Address1 = "21 West 52nd Street",
                Address2 = "",
                City = "New York",
                ZipPostalCode = "10021",
                CreatedOn = DateTime.UtcNow,
            };


            var adminRole= _customerRoleRepository.Table().Where(c => c.SystemName == "Administrators").FirstOrDefault();
            var registedRole = _customerRoleRepository.Table().Where(c => c.SystemName == "Registered").FirstOrDefault();
            customer.CustomerRoles = new Collection<CustomerRole>();
            customer.CustomerRoles.Add(adminRole);
            customer.CustomerRoles.Add(registedRole);
            customer.ShippingAddress = defaultAddress;

            customer.Addresses  =new Collection<Address>();
            customer.Addresses.Add(defaultAddress);
            _customerRepository.Insert( customer);
            return customer.Id.ToString();
        }

        private string InstallShopOwner()
        {
            var customer = new Customer()
                {
                    Active = true,
                    Username = "shopowner",
                    Password = _encryptionService.CreatePasswordHash("123456", "aabbcc", "SHA1"),
                    Email = "cc@cc.com",
                    UserGuid = Guid.NewGuid(),
                    Deleted = false,
                    CreatedOn = DateTime.Now
                };
            var defaultAddress = new Address()
            {
                FirstName = "John",
                LastName = "Smith",
                PhoneNumber = "12345678",
                MobileNumber = "1232323",
                Email = "admin@yourStore.com",
               Province = "shang hai",
                Address1 = "21 West 52nd Street",
                Address2 = "",
                City = "New York",
                ZipPostalCode = "10021",
                CreatedOn = DateTime.UtcNow,
            };


            var shopOwerRole = _customerRoleRepository.Table().Where(c => c.SystemName == "ShopOwner").FirstOrDefault();
            var registedRole = _customerRoleRepository.Table().Where(c => c.SystemName == "Registered").FirstOrDefault();

            customer.CustomerRoles = new Collection<CustomerRole>();
            customer.CustomerRoles.Add(shopOwerRole);
            customer.CustomerRoles.Add(registedRole);
            customer.ShippingAddress = defaultAddress;

            customer.Addresses = new Collection<Address>();
            customer.Addresses.Add(defaultAddress);
            _customerRepository.Insert(customer);
            return customer.Id.ToString();
        }

        private void InstallCategory()
        {
            var cat = new Category()
                {
                    CreatedOn= DateTime.Now,
                    UpdatedOn= DateTime.Now,
                    Deleted = false,
                    Description = "shirts",
                    DisplayOrder = 1,
                    Name = "shirts",
                    ParentCategoryId = 0,
                };
            _catRep.Insert( cat);


            cat = new Category()
            {
                CreatedOn= DateTime.Now,
                UpdatedOn= DateTime.Now,
                Deleted = false,
                Description = "Jeans",
                DisplayOrder = 1,
                Name = "Jeans",
                ParentCategoryId = 0,
            };
            _catRep.Insert( cat);
        }

        private void InstallBrand()
        {
            var brand = new Brand()
                {
                    Name = "AF",
                    CreatedOn= DateTime.Now,
                    UpdatedOn= DateTime.Now,
                    Published = true,
                    DisplayOrder = 1,
                    Deleted = false,
                    Description = "AF",
                };
            _brandRep.Insert( brand);
        }

        private void InstallAlipayPaymethodSetting()
        {
            var alipaySetting = new AlipayPaymethodSetting()
                {
                    AlipayKey = "key",
                    AlipayPartner = "partner",
                    AlipaySellerEmail = "email@yicommer.com"
                };

            _alipaysettingrep.Insert( alipaySetting);
        }

        private void DeleteAlipayPaymethodSetting()
        {
            var pList = _alipaysettingrep.Table().ToList();
            foreach (var p in pList)
            {
                _alipaysettingrep.Delete( p.Id);
            }
        }

        private void DeleteCategory()
        {
            var pList = _catRep.Table().ToList();
            foreach (var p in pList)
            {
                _catRep.Delete(p.Id);
            }
        }

        private void DeleteBrand()
        {
            var pList = _brandRep.Table().ToList();
            foreach (var p in pList)
            {
                _brandRep.Delete( p.Id);
            }
        }

   

        private void DeleteCustomer()
        {
            var pList = _customerRepository.Table().ToList();
            foreach (var p in pList)
            {
                _customerRepository.Delete( p.Id);
            }
        }

       

      

        

        private void DeleteOrder()
        {
            var pList = _orderRep.Table().ToList();
            foreach (var p in pList)
            {
                _orderRep.Delete( p.Id);
            }
        }

        private void DeleteProduct()
        {
            var pList = _productRepository.Table().ToList();
            foreach (var p in pList)
            {
                _productRepository.Delete( p.Id);
            }
        }

      


       
      

        private void DeleteProductAttribute()
        {
            var ss = _productAttributeRepository.Table().ToList();
            foreach (var s in ss)
            {
                _productAttributeRepository.Delete( s.Id);
            }
        }


        private void DeleteShipment()
        {
            var ss = _shipmentRecordRep.Table().ToList();
            foreach (var s in ss)
            {
                _shipmentRecordRep.Delete( s.Id);
            }
        }

        private void DeleteSpecificationAttribute()
        {
            var ss = _speficationAttributreRepostiory.Table().ToList();
            foreach (var s in ss)
            {
                _speficationAttributreRepostiory.Delete( s.Id);
            }
        }

        

        

     

        private void DeleteSystemSetting()
        {
            var ss = _systemSettingRep.Table().ToList();
            foreach (var s in ss)
            {
                _systemSettingRep.Delete( s.Id);
            }
        }

        private void InstallSystemSetting()
        {
            var ss = new SystemSetting()
                {
                    StoreLocation = "www.yicommerce.com"
                };
            _systemSettingRep.Insert( ss);
        }

        

        private void DeleteTradings()
        {
            var tradingList = _tradingRep.Table().ToList();
            foreach (var t in tradingList)
            {
                _tradingRep.Delete( t.Id);
            }

        }

        private void DeleteOrders()
        {

            var orderList = _orderRep.Table().ToList();
            foreach (var order in orderList)
            {
              
                _orderRep.Delete( order.Id);
            }

        }

       

        
        private void InstallSpecificationAttributes()
        {

            var p = new SpecificationAttribute()
                {
                    DisplayOrder = 1,
                    Name = "Screen Size",
                    Options  = new List<SpecificationAttributeOption>()
                        {
                            new SpecificationAttributeOption()
                                {
                                    SpecificationAttributeOptionName = "10.0",
                                },
                            new SpecificationAttributeOption()
                                {
                                    SpecificationAttributeOptionName = "20.0",
                                },

                        }
                };
            _speficationAttributreRepostiory.Insert( p);

           

        

            p = new SpecificationAttribute()
                {
                    DisplayOrder = 2,
                    Name = "CPU Type" ,
                    Options  = new List<SpecificationAttributeOption>()
                        {
                            new SpecificationAttributeOption()
                                {
                                    SpecificationAttributeOptionName = "Intel",
                                },
                            new SpecificationAttributeOption()
                                {
                                    SpecificationAttributeOptionName = "AMD",
                                },

                        }
                };
            _speficationAttributreRepostiory.Insert( p);


        
        }

        private void InstallProductAttribute()
        {
            var pa = new ProductAttribute()
                {
                    Description = "Color",
                    Name = "Color"
                };

            _productAttributeRepository.Insert(pa);

            pa = new ProductAttribute()
            {
                Description = "Size",
                Name = "Size"
            };

            _productAttributeRepository.Insert(pa);
        }

        private string InstallCustomer()
        {
            var customer = new Customer()
            {
                Active = true,
                Username = "zhuzhu",
                Password = _encryptionService.CreatePasswordHash("123456", "aabbcc", "SHA1"),
                Email = "ee@ee.com",
                UserGuid = Guid.NewGuid(),
                Deleted = false,
                CreatedOn = DateTime.Now
            };
            var defaultAddress = new Address()
            {
                FirstName = "Mike",
                LastName = "Yi",
                PhoneNumber = "12345678",
                MobileNumber = "1232323",
                Email = "ee@ee.com",
                Province = "shang hai",
                Address1 = "21 West 52nd Street",
                Address2 = "",
                City = "New York",
                ZipPostalCode = "10021",
                CreatedOn= DateTime.UtcNow,
            };


            var registedRole = _customerRoleRepository.Table().Where(c => c.SystemName == "Registered").FirstOrDefault();
            customer.CustomerRoles= new Collection<CustomerRole>();
            customer.CustomerRoles.Add(registedRole);
            customer.ShippingAddress = defaultAddress;
            customer.Addresses = new Collection<Address>();
            customer.Addresses.Add(defaultAddress);
            _customerRepository.Insert( customer);
            return customer.Id.ToString();
        }

        private void InstallShop(string shopOwnerId, string adminId, string customerId)
        {

            var shop = new Shop()
                {
                    ShopName = "hello world",
                    Owner= new Customer()
                        {
                            Id =shopOwnerId 
                        } 
                };
            _shopRepository.Insert(shop);

          _customerService.UpdateCustomerShop(shopOwnerId, shop.Id);

            shop = new Shop()
            {
                ShopName = "hello world",
                Owner = new Customer()
                {
                    Id = adminId
                } 
            };
            _shopRepository.Insert( shop);

          _customerService.UpdateCustomerShop(adminId, shop.Id);

            shop = new Shop()
            {
                ShopName = "hello world",
                Owner = new Customer()
                {
                    Id = customerId
                }
            };
            _shopRepository.Insert( shop);

        
          _customerService.UpdateCustomerShop(customerId, shop.Id);
        }

       




      
    }
}
